package test3;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Aug 1, 2007
 * Time: 9:42:16 PM
 * Revision: 0
 */
public class TokenGenerator
{
    private char[] dataBuf;
    private int dataPos;


    public TokenGenerator(char[] dataBuf)
    {
        this.dataBuf = dataBuf;
        dataPos = 0;
    }

    private boolean isValidTokenChar(char c)
    {
        return (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || (c == '_'));
    }

    private boolean isWhitespaceChar(char c)
    {
        return ((c == ' ') || (c == '\n') || (c == '\t'));
    }

    private void skipCComment()
    {
        dataPos += 2;

        while (dataPos < dataBuf.length && (dataBuf[dataPos] != '\n'))
            dataPos++;
    }

    private void skipCppComment()
    {
        dataPos += 2;

        while (dataPos<dataBuf.length+1)
        {
            if ((dataBuf[dataPos]=='*')&&(dataBuf[dataPos+1]=='/'))
            {
                dataPos += 2;
                return;
            }
            dataPos++;
        }
    }

    private void skipWhiteSpace()
    {
        while (true)
        {
            while (isWhitespaceChar(peekChar()))
                dataPos++;

            if (dataPos < dataBuf.length + 1)
            {
                if (dataBuf[dataPos] == '/')
                {
                    if (dataBuf[dataPos + 1] == '/')
                        skipCppComment();
                    else
                        if (dataBuf[dataPos + 1] == '*')
                            skipCComment();
                        else
                            return;
                }
                else
                    return;
            }
            else
                return;
        }
    }

    public String peekToken()
    {
        return "";
    }

    public String getToken()
    {
        String s = peekToken();
        dataPos += s.length();
        return s;
    }

    public char peekChar()
    {
        return ' ';
    }

    public char getChar()
    {
        return ' ';
    }

    public String getIdentifier()
    {
        return getToken();
    }

    public String getIdentifierWithDots()
    {
        return getToken();
    }

    public String getNumber()
    {
        return getToken();
    }

}
